package jdk.collection;

import java.util.HashMap;
import java.util.Hashtable;
import java.util.Map;

public class HashMapDemo {

    public static void main(String[] args) {
        Map<String, String> map = new HashMap();
        map.put("name", "luobinjie");
        map.put("sex", "man");
        map.entrySet();
        map.toString();
        System.out.println(map);

        Map<String, String> hashTable = new Hashtable();
        hashTable.put("name", "zyt");
        System.out.println(hashTable.get("name"));


        System.out.println("maximum-capacity: "+MAXIMUM_CAPACITY);
        System.out.println("tableSizeFor: "+tableSizeFor(127));


    }


    static final int MAXIMUM_CAPACITY = 1 << 30;

    /**
     * Returns a power of two size for the given target capacity.
     */
    static final int tableSizeFor(int cap) {
        int n = cap - 1;
        n |= n >>> 1;
        n |= n >>> 2;
        n |= n >>> 4;
        n |= n >>> 8;
        n |= n >>> 16;
        return (n < 0) ? 1 : (n >= MAXIMUM_CAPACITY) ? MAXIMUM_CAPACITY : n + 1;
    }
}
